clear
set mem 1g
set more off
prog drop _all
capture log close

pause off

	local graph1_options "ms(T) mc(black) mfc(black) c(l) lp(shortdash) lc(black)  lwidth(1.2)"
	local graph2_options "ms(O) mc(green) mfc(green) c(l) lp(dash_dot) lc(green)   lwidth(1.2)"
	local graph3_options "ms(T) mc(blue) mfc(none) c(l)   lp(longdash) lc(blue)   lwidth(1.2)"
	local graph4_options "ms(D) mc(red) mfc(red) c(l)     lp(solid) lc(red)   lwidth(1.2)"
	local graph5_options "ms(D) mc(red) mfc(none) c(l) lp(dash) lc(red)"
	local graph6_options "ms(O) mc(green) mfc(none) c(l) lp(dash) lc(green)"


set scheme s1color

****************************************************************
use out_files/sim_model_part1, clear
gen hgc13more = (educ>=13)

foreach var in hgc13more dq {

	sum `var' if age == 30
	global G`var' = `r(mean)'
	local _`var'_fitted = `r(mean)'
	
	sum `var' if age == 30 & (addiction + dq)>=1
	global Gever`var' = `r(mean)'
	local _ever`var'_fitted  = `r(mean)'
}

rename * cf_*
rename cf_id id
rename cf_age age


merge 1:1 id age using out_files_CFnoDq/sim_model_part1
gen hgc13more = (educ>=13)

foreach var in hgc13more dq {

	sum `var' if age == 30
	global G`var'_nodq = `r(mean)'
	local  _`var'_nodq = `r(mean)'
	
	sum `var' if age == 30 & (cf_addiction + cf_dq)>=1
	global Gever`var'_nodq = `r(mean)'
	local _ever`var'_nodq = `r(mean)'
}

** fitted model
disp $Ghgc13more
disp $Geverhgc13more
** CF model without smoking 
disp $Ghgc13more_nodq
disp $Geverhgc13more_nodq


****************************************************************
* Generating figures for taxation analysis 
****************************************************************

global  dir_fig_out     "../outputs"


insheet everdq igrid taxrate_dq cbc_sub gtr_sub gtr_csub dq hgc hgc12more hgc11less hgc12 hgc1315 hgc16more using out_files_optTax/ALL_outcomes.txt, clear	

gen hgc13more =  hgc1315 + hgc16more

sum everdq

local n = `r(N)' + 2
set obs  `n'

replace taxrate_dq = 0 if _n >= _N-1
replace everdq = 0 if _n == _N-1
replace everdq = 1 if _n == _N

replace dq = $Gdq if taxrate_dq == 0 & everdq ==0
replace dq = $Gdq if taxrate_dq == 0 & everdq ==1

replace hgc13more = $Ghgc13more if taxrate_dq == 0 & everdq ==0
replace hgc13more = $Geverhgc13more if taxrate_dq == 0 & everdq ==1

** everdq =0 is for the entire population; everdq = 1 is for smokers

replace taxrate_dq = taxrate_dq * 100

sum taxrate_dq 
local maxtaxrate `r(max)'

    graph twoway scatter dq taxrate_dq if everdq == 0,  mc(blue) mfc(blue) || function y = $Gdq,  lp(longdash)  lc(red) lwidth(1.2) xlabel(0(10)`maxtaxrate', valuelabel) xscale(range(0, `maxtaxrate'))  range(taxrate_dq) scheme(s1color) ysc(titlegap(2)) ylabel(, grid) legend(row(3) lab(1 "Counterfactual simulations: Excise taxation") lab(2 "Benchmark model")) legend(on region(lstyle(none))) xtitle("Additional excise tax rates (%)" ) ytitle(Smoking rate at age 30)
	graph export out_figs_optTax/fig_dqa30_BY_taxrate_dq.pdf, as(pdf) replace 	
	graph export out_figs_optTax/fig_dqa30_BY_taxrate_dq.eps, as(eps) replace 
	
	graph export $dir_fig_out/Figure_07b.pdf, as(pdf) replace 	
	graph export $dir_fig_out/Figure_07b.eps, as(eps) replace 	

****************************************************************
global educTarget          hgc13more
global evereducBenchmark   $Geverhgc13more 
global evereducNodq        $Geverhgc13more_nodq
global educBenchmark   	   $Ghgc13more 
global educNodq        	   $Ghgc13more_nodq
local  educTarget          $educTarget  
****************************************************************
	
	**  (ever smokers in the benchmark model)
   	graph twoway scatter $educTarget taxrate_dq if everdq == 1,  mc(blue) mfc(blue) || function y = $evereducBenchmark,  range(taxrate_dq) lp(longdash)  lc(red) lwidth(1.2) || function y = $evereducNodq, lp(shortdash) lc(green) lwidth(1.2) xlabel(0(10)`maxtaxrate', valuelabel) xscale(range(0, `maxtaxrate'))  range(taxrate_dq) scheme(s1color) ysc(titlegap(2)) ylabel(, grid) legend(row(3) lab(1 "Counterfactual simulations: Excise taxation") lab(2 "Benchmark model") lab(3 "Counterfactual simulation: no smoking")) legend(on region(lstyle(none))) xtitle("Additional revenue-neutral excise tax rates (%)" ) ytitle(Some college or more)
	graph export out_figs_optTax/fig_ever`educTarget'_BY_taxrate_dq.pdf, as(pdf) replace 	
	graph export out_figs_optTax/fig_ever`educTarget'_BY_taxrate_dq.pdf, as(eps) replace 	
	
	graph export $dir_fig_out/Figure_07a.pdf, as(pdf) replace 	
	graph export $dir_fig_out/Figure_07a.eps, as(eps) replace 	



saveold data_opttax, replace
!rm data_opttax.dta


**********************************************************************


capture log close

